package TCP.Client;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",8888);
        OutputStream out = socket.getOutputStream();
        InputStream in = socket.getInputStream();
        var reader = new BufferedReader(new InputStreamReader(in));
        var writer = new BufferedWriter(new OutputStreamWriter(out));
        Scanner scanner = new Scanner(System.in);
        System.out.println("[server] "+ reader.readLine());
        for(;;){
            System.out.print(">>> ");
            String command = scanner.nextLine();
            if(command.equals("exit")){
                break;
            }
            writer.write(command);
            writer.newLine();
            writer.flush();
            String response = reader.readLine();
            System.out.println("get response from "+socket.getRemoteSocketAddress().toString()+" : "+response);
        }
        socket.close();
    }
}
